{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from model.fpn import FPN\n",
    "from model.resnet import resnest50\n",
    "from collections import OrderedDict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = resnest50(True)\n",
    "# model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "FPN(\n",
       "  (lateral_convs): ModuleList(\n",
       "    (0): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))\n",
       "    (1): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1))\n",
       "    (2): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1))\n",
       "    (3): Conv2d(2048, 256, kernel_size=(1, 1), stride=(1, 1))\n",
       "  )\n",
       "  (fpn_conv): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
       ")"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fpn = FPN(in_channels=[256, 512, 1024, 2048], out_channels=256, num_outs=4)\n",
    "fpn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "_IncompatibleKeys(missing_keys=['layer1.0.se_module.fc1.weight', 'layer1.0.se_module.fc1.bias', 'layer1.0.se_module.fc2.weight', 'layer1.0.se_module.fc2.bias', 'layer1.1.se_module.fc1.weight', 'layer1.1.se_module.fc1.bias', 'layer1.1.se_module.fc2.weight', 'layer1.1.se_module.fc2.bias', 'layer1.2.se_module.fc1.weight', 'layer1.2.se_module.fc1.bias', 'layer1.2.se_module.fc2.weight', 'layer1.2.se_module.fc2.bias', 'layer2.0.se_module.fc1.weight', 'layer2.0.se_module.fc1.bias', 'layer2.0.se_module.fc2.weight', 'layer2.0.se_module.fc2.bias', 'layer2.1.se_module.fc1.weight', 'layer2.1.se_module.fc1.bias', 'layer2.1.se_module.fc2.weight', 'layer2.1.se_module.fc2.bias', 'layer2.2.se_module.fc1.weight', 'layer2.2.se_module.fc1.bias', 'layer2.2.se_module.fc2.weight', 'layer2.2.se_module.fc2.bias', 'layer2.3.se_module.fc1.weight', 'layer2.3.se_module.fc1.bias', 'layer2.3.se_module.fc2.weight', 'layer2.3.se_module.fc2.bias', 'layer3.0.se_module.fc1.weight', 'layer3.0.se_module.fc1.bias', 'layer3.0.se_module.fc2.weight', 'layer3.0.se_module.fc2.bias', 'layer3.1.se_module.fc1.weight', 'layer3.1.se_module.fc1.bias', 'layer3.1.se_module.fc2.weight', 'layer3.1.se_module.fc2.bias', 'layer3.2.se_module.fc1.weight', 'layer3.2.se_module.fc1.bias', 'layer3.2.se_module.fc2.weight', 'layer3.2.se_module.fc2.bias', 'layer3.3.se_module.fc1.weight', 'layer3.3.se_module.fc1.bias', 'layer3.3.se_module.fc2.weight', 'layer3.3.se_module.fc2.bias', 'layer3.4.se_module.fc1.weight', 'layer3.4.se_module.fc1.bias', 'layer3.4.se_module.fc2.weight', 'layer3.4.se_module.fc2.bias', 'layer3.5.se_module.fc1.weight', 'layer3.5.se_module.fc1.bias', 'layer3.5.se_module.fc2.weight', 'layer3.5.se_module.fc2.bias', 'layer4.0.se_module.fc1.weight', 'layer4.0.se_module.fc1.bias', 'layer4.0.se_module.fc2.weight', 'layer4.0.se_module.fc2.bias', 'layer4.1.se_module.fc1.weight', 'layer4.1.se_module.fc1.bias', 'layer4.1.se_module.fc2.weight', 'layer4.1.se_module.fc2.bias', 'layer4.2.se_module.fc1.weight', 'layer4.2.se_module.fc1.bias', 'layer4.2.se_module.fc2.weight', 'layer4.2.se_module.fc2.bias'], unexpected_keys=[])"
      ]
     },
     "metadata": {},
     "execution_count": 14
    }
   ],
   "source": [
    "pretrain_model = torch.load(\"model_state/mask_rcnn_s50_fpn_syncbn-backbone+head_mstrain_1x_coco_20200926_125503-8a2c3d47.pth\")\n",
    "\n",
    "#处理backbone\n",
    "new_backbone_statedict = OrderedDict()\n",
    "for key in pretrain_model['state_dict']:\n",
    "    if key.startswith('backbone'):\n",
    "        new_backbone_statedict[key[len(\"backbone.\"):]] = pretrain_model['state_dict'][key]\n",
    "torch.save(new_backbone_statedict, \"coco_backbone_statedict.pth\")\n",
    "model.load_state_dict(new_backbone_statedict, strict=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "stem.0.weight\nstem.1.weight\nstem.1.bias\nstem.1.running_mean\nstem.1.running_var\nstem.1.num_batches_tracked\nstem.3.weight\nstem.4.weight\nstem.4.bias\nstem.4.running_mean\nstem.4.running_var\nstem.4.num_batches_tracked\nstem.6.weight\nstem.7.weight\nstem.7.bias\nstem.7.running_mean\nstem.7.running_var\nstem.7.num_batches_tracked\nlayer1.0.conv1.weight\nlayer1.0.bn1.weight\nlayer1.0.bn1.bias\nlayer1.0.bn1.running_mean\nlayer1.0.bn1.running_var\nlayer1.0.bn1.num_batches_tracked\nlayer1.0.conv2.conv.weight\nlayer1.0.conv2.bn0.weight\nlayer1.0.conv2.bn0.bias\nlayer1.0.conv2.bn0.running_mean\nlayer1.0.conv2.bn0.running_var\nlayer1.0.conv2.bn0.num_batches_tracked\nlayer1.0.conv2.fc1.weight\nlayer1.0.conv2.fc1.bias\nlayer1.0.conv2.bn1.weight\nlayer1.0.conv2.bn1.bias\nlayer1.0.conv2.bn1.running_mean\nlayer1.0.conv2.bn1.running_var\nlayer1.0.conv2.bn1.num_batches_tracked\nlayer1.0.conv2.fc2.weight\nlayer1.0.conv2.fc2.bias\nlayer1.0.conv3.weight\nlayer1.0.bn3.weight\nlayer1.0.bn3.bias\nlayer1.0.bn3.running_mean\nlayer1.0.bn3.running_var\nlayer1.0.bn3.num_batches_tracked\nlayer1.0.downsample.1.weight\nlayer1.0.downsample.2.weight\nlayer1.0.downsample.2.bias\nlayer1.0.downsample.2.running_mean\nlayer1.0.downsample.2.running_var\nlayer1.0.downsample.2.num_batches_tracked\nlayer1.0.se_module.fc1.weight\nlayer1.0.se_module.fc1.bias\nlayer1.0.se_module.fc2.weight\nlayer1.0.se_module.fc2.bias\nlayer1.1.conv1.weight\nlayer1.1.bn1.weight\nlayer1.1.bn1.bias\nlayer1.1.bn1.running_mean\nlayer1.1.bn1.running_var\nlayer1.1.bn1.num_batches_tracked\nlayer1.1.conv2.conv.weight\nlayer1.1.conv2.bn0.weight\nlayer1.1.conv2.bn0.bias\nlayer1.1.conv2.bn0.running_mean\nlayer1.1.conv2.bn0.running_var\nlayer1.1.conv2.bn0.num_batches_tracked\nlayer1.1.conv2.fc1.weight\nlayer1.1.conv2.fc1.bias\nlayer1.1.conv2.bn1.weight\nlayer1.1.conv2.bn1.bias\nlayer1.1.conv2.bn1.running_mean\nlayer1.1.conv2.bn1.running_var\nlayer1.1.conv2.bn1.num_batches_tracked\nlayer1.1.conv2.fc2.weight\nlayer1.1.conv2.fc2.bias\nlayer1.1.conv3.weight\nlayer1.1.bn3.weight\nlayer1.1.bn3.bias\nlayer1.1.bn3.running_mean\nlayer1.1.bn3.running_var\nlayer1.1.bn3.num_batches_tracked\nlayer1.1.se_module.fc1.weight\nlayer1.1.se_module.fc1.bias\nlayer1.1.se_module.fc2.weight\nlayer1.1.se_module.fc2.bias\nlayer1.2.conv1.weight\nlayer1.2.bn1.weight\nlayer1.2.bn1.bias\nlayer1.2.bn1.running_mean\nlayer1.2.bn1.running_var\nlayer1.2.bn1.num_batches_tracked\nlayer1.2.conv2.conv.weight\nlayer1.2.conv2.bn0.weight\nlayer1.2.conv2.bn0.bias\nlayer1.2.conv2.bn0.running_mean\nlayer1.2.conv2.bn0.running_var\nlayer1.2.conv2.bn0.num_batches_tracked\nlayer1.2.conv2.fc1.weight\nlayer1.2.conv2.fc1.bias\nlayer1.2.conv2.bn1.weight\nlayer1.2.conv2.bn1.bias\nlayer1.2.conv2.bn1.running_mean\nlayer1.2.conv2.bn1.running_var\nlayer1.2.conv2.bn1.num_batches_tracked\nlayer1.2.conv2.fc2.weight\nlayer1.2.conv2.fc2.bias\nlayer1.2.conv3.weight\nlayer1.2.bn3.weight\nlayer1.2.bn3.bias\nlayer1.2.bn3.running_mean\nlayer1.2.bn3.running_var\nlayer1.2.bn3.num_batches_tracked\nlayer1.2.se_module.fc1.weight\nlayer1.2.se_module.fc1.bias\nlayer1.2.se_module.fc2.weight\nlayer1.2.se_module.fc2.bias\nlayer2.0.conv1.weight\nlayer2.0.bn1.weight\nlayer2.0.bn1.bias\nlayer2.0.bn1.running_mean\nlayer2.0.bn1.running_var\nlayer2.0.bn1.num_batches_tracked\nlayer2.0.conv2.conv.weight\nlayer2.0.conv2.bn0.weight\nlayer2.0.conv2.bn0.bias\nlayer2.0.conv2.bn0.running_mean\nlayer2.0.conv2.bn0.running_var\nlayer2.0.conv2.bn0.num_batches_tracked\nlayer2.0.conv2.fc1.weight\nlayer2.0.conv2.fc1.bias\nlayer2.0.conv2.bn1.weight\nlayer2.0.conv2.bn1.bias\nlayer2.0.conv2.bn1.running_mean\nlayer2.0.conv2.bn1.running_var\nlayer2.0.conv2.bn1.num_batches_tracked\nlayer2.0.conv2.fc2.weight\nlayer2.0.conv2.fc2.bias\nlayer2.0.conv3.weight\nlayer2.0.bn3.weight\nlayer2.0.bn3.bias\nlayer2.0.bn3.running_mean\nlayer2.0.bn3.running_var\nlayer2.0.bn3.num_batches_tracked\nlayer2.0.downsample.1.weight\nlayer2.0.downsample.2.weight\nlayer2.0.downsample.2.bias\nlayer2.0.downsample.2.running_mean\nlayer2.0.downsample.2.running_var\nlayer2.0.downsample.2.num_batches_tracked\nlayer2.0.se_module.fc1.weight\nlayer2.0.se_module.fc1.bias\nlayer2.0.se_module.fc2.weight\nlayer2.0.se_module.fc2.bias\nlayer2.1.conv1.weight\nlayer2.1.bn1.weight\nlayer2.1.bn1.bias\nlayer2.1.bn1.running_mean\nlayer2.1.bn1.running_var\nlayer2.1.bn1.num_batches_tracked\nlayer2.1.conv2.conv.weight\nlayer2.1.conv2.bn0.weight\nlayer2.1.conv2.bn0.bias\nlayer2.1.conv2.bn0.running_mean\nlayer2.1.conv2.bn0.running_var\nlayer2.1.conv2.bn0.num_batches_tracked\nlayer2.1.conv2.fc1.weight\nlayer2.1.conv2.fc1.bias\nlayer2.1.conv2.bn1.weight\nlayer2.1.conv2.bn1.bias\nlayer2.1.conv2.bn1.running_mean\nlayer2.1.conv2.bn1.running_var\nlayer2.1.conv2.bn1.num_batches_tracked\nlayer2.1.conv2.fc2.weight\nlayer2.1.conv2.fc2.bias\nlayer2.1.conv3.weight\nlayer2.1.bn3.weight\nlayer2.1.bn3.bias\nlayer2.1.bn3.running_mean\nlayer2.1.bn3.running_var\nlayer2.1.bn3.num_batches_tracked\nlayer2.1.se_module.fc1.weight\nlayer2.1.se_module.fc1.bias\nlayer2.1.se_module.fc2.weight\nlayer2.1.se_module.fc2.bias\nlayer2.2.conv1.weight\nlayer2.2.bn1.weight\nlayer2.2.bn1.bias\nlayer2.2.bn1.running_mean\nlayer2.2.bn1.running_var\nlayer2.2.bn1.num_batches_tracked\nlayer2.2.conv2.conv.weight\nlayer2.2.conv2.bn0.weight\nlayer2.2.conv2.bn0.bias\nlayer2.2.conv2.bn0.running_mean\nlayer2.2.conv2.bn0.running_var\nlayer2.2.conv2.bn0.num_batches_tracked\nlayer2.2.conv2.fc1.weight\nlayer2.2.conv2.fc1.bias\nlayer2.2.conv2.bn1.weight\nlayer2.2.conv2.bn1.bias\nlayer2.2.conv2.bn1.running_mean\nlayer2.2.conv2.bn1.running_var\nlayer2.2.conv2.bn1.num_batches_tracked\nlayer2.2.conv2.fc2.weight\nlayer2.2.conv2.fc2.bias\nlayer2.2.conv3.weight\nlayer2.2.bn3.weight\nlayer2.2.bn3.bias\nlayer2.2.bn3.running_mean\nlayer2.2.bn3.running_var\nlayer2.2.bn3.num_batches_tracked\nlayer2.2.se_module.fc1.weight\nlayer2.2.se_module.fc1.bias\nlayer2.2.se_module.fc2.weight\nlayer2.2.se_module.fc2.bias\nlayer2.3.conv1.weight\nlayer2.3.bn1.weight\nlayer2.3.bn1.bias\nlayer2.3.bn1.running_mean\nlayer2.3.bn1.running_var\nlayer2.3.bn1.num_batches_tracked\nlayer2.3.conv2.conv.weight\nlayer2.3.conv2.bn0.weight\nlayer2.3.conv2.bn0.bias\nlayer2.3.conv2.bn0.running_mean\nlayer2.3.conv2.bn0.running_var\nlayer2.3.conv2.bn0.num_batches_tracked\nlayer2.3.conv2.fc1.weight\nlayer2.3.conv2.fc1.bias\nlayer2.3.conv2.bn1.weight\nlayer2.3.conv2.bn1.bias\nlayer2.3.conv2.bn1.running_mean\nlayer2.3.conv2.bn1.running_var\nlayer2.3.conv2.bn1.num_batches_tracked\nlayer2.3.conv2.fc2.weight\nlayer2.3.conv2.fc2.bias\nlayer2.3.conv3.weight\nlayer2.3.bn3.weight\nlayer2.3.bn3.bias\nlayer2.3.bn3.running_mean\nlayer2.3.bn3.running_var\nlayer2.3.bn3.num_batches_tracked\nlayer2.3.se_module.fc1.weight\nlayer2.3.se_module.fc1.bias\nlayer2.3.se_module.fc2.weight\nlayer2.3.se_module.fc2.bias\nlayer3.0.conv1.weight\nlayer3.0.bn1.weight\nlayer3.0.bn1.bias\nlayer3.0.bn1.running_mean\nlayer3.0.bn1.running_var\nlayer3.0.bn1.num_batches_tracked\nlayer3.0.conv2.conv.weight\nlayer3.0.conv2.bn0.weight\nlayer3.0.conv2.bn0.bias\nlayer3.0.conv2.bn0.running_mean\nlayer3.0.conv2.bn0.running_var\nlayer3.0.conv2.bn0.num_batches_tracked\nlayer3.0.conv2.fc1.weight\nlayer3.0.conv2.fc1.bias\nlayer3.0.conv2.bn1.weight\nlayer3.0.conv2.bn1.bias\nlayer3.0.conv2.bn1.running_mean\nlayer3.0.conv2.bn1.running_var\nlayer3.0.conv2.bn1.num_batches_tracked\nlayer3.0.conv2.fc2.weight\nlayer3.0.conv2.fc2.bias\nlayer3.0.conv3.weight\nlayer3.0.bn3.weight\nlayer3.0.bn3.bias\nlayer3.0.bn3.running_mean\nlayer3.0.bn3.running_var\nlayer3.0.bn3.num_batches_tracked\nlayer3.0.downsample.1.weight\nlayer3.0.downsample.2.weight\nlayer3.0.downsample.2.bias\nlayer3.0.downsample.2.running_mean\nlayer3.0.downsample.2.running_var\nlayer3.0.downsample.2.num_batches_tracked\nlayer3.0.se_module.fc1.weight\nlayer3.0.se_module.fc1.bias\nlayer3.0.se_module.fc2.weight\nlayer3.0.se_module.fc2.bias\nlayer3.1.conv1.weight\nlayer3.1.bn1.weight\nlayer3.1.bn1.bias\nlayer3.1.bn1.running_mean\nlayer3.1.bn1.running_var\nlayer3.1.bn1.num_batches_tracked\nlayer3.1.conv2.conv.weight\nlayer3.1.conv2.bn0.weight\nlayer3.1.conv2.bn0.bias\nlayer3.1.conv2.bn0.running_mean\nlayer3.1.conv2.bn0.running_var\nlayer3.1.conv2.bn0.num_batches_tracked\nlayer3.1.conv2.fc1.weight\nlayer3.1.conv2.fc1.bias\nlayer3.1.conv2.bn1.weight\nlayer3.1.conv2.bn1.bias\nlayer3.1.conv2.bn1.running_mean\nlayer3.1.conv2.bn1.running_var\nlayer3.1.conv2.bn1.num_batches_tracked\nlayer3.1.conv2.fc2.weight\nlayer3.1.conv2.fc2.bias\nlayer3.1.conv3.weight\nlayer3.1.bn3.weight\nlayer3.1.bn3.bias\nlayer3.1.bn3.running_mean\nlayer3.1.bn3.running_var\nlayer3.1.bn3.num_batches_tracked\nlayer3.1.se_module.fc1.weight\nlayer3.1.se_module.fc1.bias\nlayer3.1.se_module.fc2.weight\nlayer3.1.se_module.fc2.bias\nlayer3.2.conv1.weight\nlayer3.2.bn1.weight\nlayer3.2.bn1.bias\nlayer3.2.bn1.running_mean\nlayer3.2.bn1.running_var\nlayer3.2.bn1.num_batches_tracked\nlayer3.2.conv2.conv.weight\nlayer3.2.conv2.bn0.weight\nlayer3.2.conv2.bn0.bias\nlayer3.2.conv2.bn0.running_mean\nlayer3.2.conv2.bn0.running_var\nlayer3.2.conv2.bn0.num_batches_tracked\nlayer3.2.conv2.fc1.weight\nlayer3.2.conv2.fc1.bias\nlayer3.2.conv2.bn1.weight\nlayer3.2.conv2.bn1.bias\nlayer3.2.conv2.bn1.running_mean\nlayer3.2.conv2.bn1.running_var\nlayer3.2.conv2.bn1.num_batches_tracked\nlayer3.2.conv2.fc2.weight\nlayer3.2.conv2.fc2.bias\nlayer3.2.conv3.weight\nlayer3.2.bn3.weight\nlayer3.2.bn3.bias\nlayer3.2.bn3.running_mean\nlayer3.2.bn3.running_var\nlayer3.2.bn3.num_batches_tracked\nlayer3.2.se_module.fc1.weight\nlayer3.2.se_module.fc1.bias\nlayer3.2.se_module.fc2.weight\nlayer3.2.se_module.fc2.bias\nlayer3.3.conv1.weight\nlayer3.3.bn1.weight\nlayer3.3.bn1.bias\nlayer3.3.bn1.running_mean\nlayer3.3.bn1.running_var\nlayer3.3.bn1.num_batches_tracked\nlayer3.3.conv2.conv.weight\nlayer3.3.conv2.bn0.weight\nlayer3.3.conv2.bn0.bias\nlayer3.3.conv2.bn0.running_mean\nlayer3.3.conv2.bn0.running_var\nlayer3.3.conv2.bn0.num_batches_tracked\nlayer3.3.conv2.fc1.weight\nlayer3.3.conv2.fc1.bias\nlayer3.3.conv2.bn1.weight\nlayer3.3.conv2.bn1.bias\nlayer3.3.conv2.bn1.running_mean\nlayer3.3.conv2.bn1.running_var\nlayer3.3.conv2.bn1.num_batches_tracked\nlayer3.3.conv2.fc2.weight\nlayer3.3.conv2.fc2.bias\nlayer3.3.conv3.weight\nlayer3.3.bn3.weight\nlayer3.3.bn3.bias\nlayer3.3.bn3.running_mean\nlayer3.3.bn3.running_var\nlayer3.3.bn3.num_batches_tracked\nlayer3.3.se_module.fc1.weight\nlayer3.3.se_module.fc1.bias\nlayer3.3.se_module.fc2.weight\nlayer3.3.se_module.fc2.bias\nlayer3.4.conv1.weight\nlayer3.4.bn1.weight\nlayer3.4.bn1.bias\nlayer3.4.bn1.running_mean\nlayer3.4.bn1.running_var\nlayer3.4.bn1.num_batches_tracked\nlayer3.4.conv2.conv.weight\nlayer3.4.conv2.bn0.weight\nlayer3.4.conv2.bn0.bias\nlayer3.4.conv2.bn0.running_mean\nlayer3.4.conv2.bn0.running_var\nlayer3.4.conv2.bn0.num_batches_tracked\nlayer3.4.conv2.fc1.weight\nlayer3.4.conv2.fc1.bias\nlayer3.4.conv2.bn1.weight\nlayer3.4.conv2.bn1.bias\nlayer3.4.conv2.bn1.running_mean\nlayer3.4.conv2.bn1.running_var\nlayer3.4.conv2.bn1.num_batches_tracked\nlayer3.4.conv2.fc2.weight\nlayer3.4.conv2.fc2.bias\nlayer3.4.conv3.weight\nlayer3.4.bn3.weight\nlayer3.4.bn3.bias\nlayer3.4.bn3.running_mean\nlayer3.4.bn3.running_var\nlayer3.4.bn3.num_batches_tracked\nlayer3.4.se_module.fc1.weight\nlayer3.4.se_module.fc1.bias\nlayer3.4.se_module.fc2.weight\nlayer3.4.se_module.fc2.bias\nlayer3.5.conv1.weight\nlayer3.5.bn1.weight\nlayer3.5.bn1.bias\nlayer3.5.bn1.running_mean\nlayer3.5.bn1.running_var\nlayer3.5.bn1.num_batches_tracked\nlayer3.5.conv2.conv.weight\nlayer3.5.conv2.bn0.weight\nlayer3.5.conv2.bn0.bias\nlayer3.5.conv2.bn0.running_mean\nlayer3.5.conv2.bn0.running_var\nlayer3.5.conv2.bn0.num_batches_tracked\nlayer3.5.conv2.fc1.weight\nlayer3.5.conv2.fc1.bias\nlayer3.5.conv2.bn1.weight\nlayer3.5.conv2.bn1.bias\nlayer3.5.conv2.bn1.running_mean\nlayer3.5.conv2.bn1.running_var\nlayer3.5.conv2.bn1.num_batches_tracked\nlayer3.5.conv2.fc2.weight\nlayer3.5.conv2.fc2.bias\nlayer3.5.conv3.weight\nlayer3.5.bn3.weight\nlayer3.5.bn3.bias\nlayer3.5.bn3.running_mean\nlayer3.5.bn3.running_var\nlayer3.5.bn3.num_batches_tracked\nlayer3.5.se_module.fc1.weight\nlayer3.5.se_module.fc1.bias\nlayer3.5.se_module.fc2.weight\nlayer3.5.se_module.fc2.bias\nlayer4.0.conv1.weight\nlayer4.0.bn1.weight\nlayer4.0.bn1.bias\nlayer4.0.bn1.running_mean\nlayer4.0.bn1.running_var\nlayer4.0.bn1.num_batches_tracked\nlayer4.0.conv2.conv.weight\nlayer4.0.conv2.bn0.weight\nlayer4.0.conv2.bn0.bias\nlayer4.0.conv2.bn0.running_mean\nlayer4.0.conv2.bn0.running_var\nlayer4.0.conv2.bn0.num_batches_tracked\nlayer4.0.conv2.fc1.weight\nlayer4.0.conv2.fc1.bias\nlayer4.0.conv2.bn1.weight\nlayer4.0.conv2.bn1.bias\nlayer4.0.conv2.bn1.running_mean\nlayer4.0.conv2.bn1.running_var\nlayer4.0.conv2.bn1.num_batches_tracked\nlayer4.0.conv2.fc2.weight\nlayer4.0.conv2.fc2.bias\nlayer4.0.conv3.weight\nlayer4.0.bn3.weight\nlayer4.0.bn3.bias\nlayer4.0.bn3.running_mean\nlayer4.0.bn3.running_var\nlayer4.0.bn3.num_batches_tracked\nlayer4.0.downsample.1.weight\nlayer4.0.downsample.2.weight\nlayer4.0.downsample.2.bias\nlayer4.0.downsample.2.running_mean\nlayer4.0.downsample.2.running_var\nlayer4.0.downsample.2.num_batches_tracked\nlayer4.0.se_module.fc1.weight\nlayer4.0.se_module.fc1.bias\nlayer4.0.se_module.fc2.weight\nlayer4.0.se_module.fc2.bias\nlayer4.1.conv1.weight\nlayer4.1.bn1.weight\nlayer4.1.bn1.bias\nlayer4.1.bn1.running_mean\nlayer4.1.bn1.running_var\nlayer4.1.bn1.num_batches_tracked\nlayer4.1.conv2.conv.weight\nlayer4.1.conv2.bn0.weight\nlayer4.1.conv2.bn0.bias\nlayer4.1.conv2.bn0.running_mean\nlayer4.1.conv2.bn0.running_var\nlayer4.1.conv2.bn0.num_batches_tracked\nlayer4.1.conv2.fc1.weight\nlayer4.1.conv2.fc1.bias\nlayer4.1.conv2.bn1.weight\nlayer4.1.conv2.bn1.bias\nlayer4.1.conv2.bn1.running_mean\nlayer4.1.conv2.bn1.running_var\nlayer4.1.conv2.bn1.num_batches_tracked\nlayer4.1.conv2.fc2.weight\nlayer4.1.conv2.fc2.bias\nlayer4.1.conv3.weight\nlayer4.1.bn3.weight\nlayer4.1.bn3.bias\nlayer4.1.bn3.running_mean\nlayer4.1.bn3.running_var\nlayer4.1.bn3.num_batches_tracked\nlayer4.1.se_module.fc1.weight\nlayer4.1.se_module.fc1.bias\nlayer4.1.se_module.fc2.weight\nlayer4.1.se_module.fc2.bias\nlayer4.2.conv1.weight\nlayer4.2.bn1.weight\nlayer4.2.bn1.bias\nlayer4.2.bn1.running_mean\nlayer4.2.bn1.running_var\nlayer4.2.bn1.num_batches_tracked\nlayer4.2.conv2.conv.weight\nlayer4.2.conv2.bn0.weight\nlayer4.2.conv2.bn0.bias\nlayer4.2.conv2.bn0.running_mean\nlayer4.2.conv2.bn0.running_var\nlayer4.2.conv2.bn0.num_batches_tracked\nlayer4.2.conv2.fc1.weight\nlayer4.2.conv2.fc1.bias\nlayer4.2.conv2.bn1.weight\nlayer4.2.conv2.bn1.bias\nlayer4.2.conv2.bn1.running_mean\nlayer4.2.conv2.bn1.running_var\nlayer4.2.conv2.bn1.num_batches_tracked\nlayer4.2.conv2.fc2.weight\nlayer4.2.conv2.fc2.bias\nlayer4.2.conv3.weight\nlayer4.2.bn3.weight\nlayer4.2.bn3.bias\nlayer4.2.bn3.running_mean\nlayer4.2.bn3.running_var\nlayer4.2.bn3.num_batches_tracked\nlayer4.2.se_module.fc1.weight\nlayer4.2.se_module.fc1.bias\nlayer4.2.se_module.fc2.weight\nlayer4.2.se_module.fc2.bias\n"
     ]
    }
   ],
   "source": [
    "for key in model.state_dict():\n",
    "    print(key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "stem.0.weight\nstem.1.weight\nstem.1.bias\nstem.1.running_mean\nstem.1.running_var\nstem.1.num_batches_tracked\nstem.3.weight\nstem.4.weight\nstem.4.bias\nstem.4.running_mean\nstem.4.running_var\nstem.4.num_batches_tracked\nstem.6.weight\nstem.7.weight\nstem.7.bias\nstem.7.running_mean\nstem.7.running_var\nstem.7.num_batches_tracked\nlayer1.0.conv1.weight\nlayer1.0.bn1.weight\nlayer1.0.bn1.bias\nlayer1.0.bn1.running_mean\nlayer1.0.bn1.running_var\nlayer1.0.bn1.num_batches_tracked\nlayer1.0.conv2.conv.weight\nlayer1.0.conv2.bn0.weight\nlayer1.0.conv2.bn0.bias\nlayer1.0.conv2.bn0.running_mean\nlayer1.0.conv2.bn0.running_var\nlayer1.0.conv2.bn0.num_batches_tracked\nlayer1.0.conv2.fc1.weight\nlayer1.0.conv2.fc1.bias\nlayer1.0.conv2.bn1.weight\nlayer1.0.conv2.bn1.bias\nlayer1.0.conv2.bn1.running_mean\nlayer1.0.conv2.bn1.running_var\nlayer1.0.conv2.bn1.num_batches_tracked\nlayer1.0.conv2.fc2.weight\nlayer1.0.conv2.fc2.bias\nlayer1.0.conv3.weight\nlayer1.0.bn3.weight\nlayer1.0.bn3.bias\nlayer1.0.bn3.running_mean\nlayer1.0.bn3.running_var\nlayer1.0.bn3.num_batches_tracked\nlayer1.0.downsample.1.weight\nlayer1.0.downsample.2.weight\nlayer1.0.downsample.2.bias\nlayer1.0.downsample.2.running_mean\nlayer1.0.downsample.2.running_var\nlayer1.0.downsample.2.num_batches_tracked\nlayer1.1.conv1.weight\nlayer1.1.bn1.weight\nlayer1.1.bn1.bias\nlayer1.1.bn1.running_mean\nlayer1.1.bn1.running_var\nlayer1.1.bn1.num_batches_tracked\nlayer1.1.conv2.conv.weight\nlayer1.1.conv2.bn0.weight\nlayer1.1.conv2.bn0.bias\nlayer1.1.conv2.bn0.running_mean\nlayer1.1.conv2.bn0.running_var\nlayer1.1.conv2.bn0.num_batches_tracked\nlayer1.1.conv2.fc1.weight\nlayer1.1.conv2.fc1.bias\nlayer1.1.conv2.bn1.weight\nlayer1.1.conv2.bn1.bias\nlayer1.1.conv2.bn1.running_mean\nlayer1.1.conv2.bn1.running_var\nlayer1.1.conv2.bn1.num_batches_tracked\nlayer1.1.conv2.fc2.weight\nlayer1.1.conv2.fc2.bias\nlayer1.1.conv3.weight\nlayer1.1.bn3.weight\nlayer1.1.bn3.bias\nlayer1.1.bn3.running_mean\nlayer1.1.bn3.running_var\nlayer1.1.bn3.num_batches_tracked\nlayer1.2.conv1.weight\nlayer1.2.bn1.weight\nlayer1.2.bn1.bias\nlayer1.2.bn1.running_mean\nlayer1.2.bn1.running_var\nlayer1.2.bn1.num_batches_tracked\nlayer1.2.conv2.conv.weight\nlayer1.2.conv2.bn0.weight\nlayer1.2.conv2.bn0.bias\nlayer1.2.conv2.bn0.running_mean\nlayer1.2.conv2.bn0.running_var\nlayer1.2.conv2.bn0.num_batches_tracked\nlayer1.2.conv2.fc1.weight\nlayer1.2.conv2.fc1.bias\nlayer1.2.conv2.bn1.weight\nlayer1.2.conv2.bn1.bias\nlayer1.2.conv2.bn1.running_mean\nlayer1.2.conv2.bn1.running_var\nlayer1.2.conv2.bn1.num_batches_tracked\nlayer1.2.conv2.fc2.weight\nlayer1.2.conv2.fc2.bias\nlayer1.2.conv3.weight\nlayer1.2.bn3.weight\nlayer1.2.bn3.bias\nlayer1.2.bn3.running_mean\nlayer1.2.bn3.running_var\nlayer1.2.bn3.num_batches_tracked\nlayer2.0.conv1.weight\nlayer2.0.bn1.weight\nlayer2.0.bn1.bias\nlayer2.0.bn1.running_mean\nlayer2.0.bn1.running_var\nlayer2.0.bn1.num_batches_tracked\nlayer2.0.conv2.conv.weight\nlayer2.0.conv2.bn0.weight\nlayer2.0.conv2.bn0.bias\nlayer2.0.conv2.bn0.running_mean\nlayer2.0.conv2.bn0.running_var\nlayer2.0.conv2.bn0.num_batches_tracked\nlayer2.0.conv2.fc1.weight\nlayer2.0.conv2.fc1.bias\nlayer2.0.conv2.bn1.weight\nlayer2.0.conv2.bn1.bias\nlayer2.0.conv2.bn1.running_mean\nlayer2.0.conv2.bn1.running_var\nlayer2.0.conv2.bn1.num_batches_tracked\nlayer2.0.conv2.fc2.weight\nlayer2.0.conv2.fc2.bias\nlayer2.0.conv3.weight\nlayer2.0.bn3.weight\nlayer2.0.bn3.bias\nlayer2.0.bn3.running_mean\nlayer2.0.bn3.running_var\nlayer2.0.bn3.num_batches_tracked\nlayer2.0.downsample.1.weight\nlayer2.0.downsample.2.weight\nlayer2.0.downsample.2.bias\nlayer2.0.downsample.2.running_mean\nlayer2.0.downsample.2.running_var\nlayer2.0.downsample.2.num_batches_tracked\nlayer2.1.conv1.weight\nlayer2.1.bn1.weight\nlayer2.1.bn1.bias\nlayer2.1.bn1.running_mean\nlayer2.1.bn1.running_var\nlayer2.1.bn1.num_batches_tracked\nlayer2.1.conv2.conv.weight\nlayer2.1.conv2.bn0.weight\nlayer2.1.conv2.bn0.bias\nlayer2.1.conv2.bn0.running_mean\nlayer2.1.conv2.bn0.running_var\nlayer2.1.conv2.bn0.num_batches_tracked\nlayer2.1.conv2.fc1.weight\nlayer2.1.conv2.fc1.bias\nlayer2.1.conv2.bn1.weight\nlayer2.1.conv2.bn1.bias\nlayer2.1.conv2.bn1.running_mean\nlayer2.1.conv2.bn1.running_var\nlayer2.1.conv2.bn1.num_batches_tracked\nlayer2.1.conv2.fc2.weight\nlayer2.1.conv2.fc2.bias\nlayer2.1.conv3.weight\nlayer2.1.bn3.weight\nlayer2.1.bn3.bias\nlayer2.1.bn3.running_mean\nlayer2.1.bn3.running_var\nlayer2.1.bn3.num_batches_tracked\nlayer2.2.conv1.weight\nlayer2.2.bn1.weight\nlayer2.2.bn1.bias\nlayer2.2.bn1.running_mean\nlayer2.2.bn1.running_var\nlayer2.2.bn1.num_batches_tracked\nlayer2.2.conv2.conv.weight\nlayer2.2.conv2.bn0.weight\nlayer2.2.conv2.bn0.bias\nlayer2.2.conv2.bn0.running_mean\nlayer2.2.conv2.bn0.running_var\nlayer2.2.conv2.bn0.num_batches_tracked\nlayer2.2.conv2.fc1.weight\nlayer2.2.conv2.fc1.bias\nlayer2.2.conv2.bn1.weight\nlayer2.2.conv2.bn1.bias\nlayer2.2.conv2.bn1.running_mean\nlayer2.2.conv2.bn1.running_var\nlayer2.2.conv2.bn1.num_batches_tracked\nlayer2.2.conv2.fc2.weight\nlayer2.2.conv2.fc2.bias\nlayer2.2.conv3.weight\nlayer2.2.bn3.weight\nlayer2.2.bn3.bias\nlayer2.2.bn3.running_mean\nlayer2.2.bn3.running_var\nlayer2.2.bn3.num_batches_tracked\nlayer2.3.conv1.weight\nlayer2.3.bn1.weight\nlayer2.3.bn1.bias\nlayer2.3.bn1.running_mean\nlayer2.3.bn1.running_var\nlayer2.3.bn1.num_batches_tracked\nlayer2.3.conv2.conv.weight\nlayer2.3.conv2.bn0.weight\nlayer2.3.conv2.bn0.bias\nlayer2.3.conv2.bn0.running_mean\nlayer2.3.conv2.bn0.running_var\nlayer2.3.conv2.bn0.num_batches_tracked\nlayer2.3.conv2.fc1.weight\nlayer2.3.conv2.fc1.bias\nlayer2.3.conv2.bn1.weight\nlayer2.3.conv2.bn1.bias\nlayer2.3.conv2.bn1.running_mean\nlayer2.3.conv2.bn1.running_var\nlayer2.3.conv2.bn1.num_batches_tracked\nlayer2.3.conv2.fc2.weight\nlayer2.3.conv2.fc2.bias\nlayer2.3.conv3.weight\nlayer2.3.bn3.weight\nlayer2.3.bn3.bias\nlayer2.3.bn3.running_mean\nlayer2.3.bn3.running_var\nlayer2.3.bn3.num_batches_tracked\nlayer3.0.conv1.weight\nlayer3.0.bn1.weight\nlayer3.0.bn1.bias\nlayer3.0.bn1.running_mean\nlayer3.0.bn1.running_var\nlayer3.0.bn1.num_batches_tracked\nlayer3.0.conv2.conv.weight\nlayer3.0.conv2.bn0.weight\nlayer3.0.conv2.bn0.bias\nlayer3.0.conv2.bn0.running_mean\nlayer3.0.conv2.bn0.running_var\nlayer3.0.conv2.bn0.num_batches_tracked\nlayer3.0.conv2.fc1.weight\nlayer3.0.conv2.fc1.bias\nlayer3.0.conv2.bn1.weight\nlayer3.0.conv2.bn1.bias\nlayer3.0.conv2.bn1.running_mean\nlayer3.0.conv2.bn1.running_var\nlayer3.0.conv2.bn1.num_batches_tracked\nlayer3.0.conv2.fc2.weight\nlayer3.0.conv2.fc2.bias\nlayer3.0.conv3.weight\nlayer3.0.bn3.weight\nlayer3.0.bn3.bias\nlayer3.0.bn3.running_mean\nlayer3.0.bn3.running_var\nlayer3.0.bn3.num_batches_tracked\nlayer3.0.downsample.1.weight\nlayer3.0.downsample.2.weight\nlayer3.0.downsample.2.bias\nlayer3.0.downsample.2.running_mean\nlayer3.0.downsample.2.running_var\nlayer3.0.downsample.2.num_batches_tracked\nlayer3.1.conv1.weight\nlayer3.1.bn1.weight\nlayer3.1.bn1.bias\nlayer3.1.bn1.running_mean\nlayer3.1.bn1.running_var\nlayer3.1.bn1.num_batches_tracked\nlayer3.1.conv2.conv.weight\nlayer3.1.conv2.bn0.weight\nlayer3.1.conv2.bn0.bias\nlayer3.1.conv2.bn0.running_mean\nlayer3.1.conv2.bn0.running_var\nlayer3.1.conv2.bn0.num_batches_tracked\nlayer3.1.conv2.fc1.weight\nlayer3.1.conv2.fc1.bias\nlayer3.1.conv2.bn1.weight\nlayer3.1.conv2.bn1.bias\nlayer3.1.conv2.bn1.running_mean\nlayer3.1.conv2.bn1.running_var\nlayer3.1.conv2.bn1.num_batches_tracked\nlayer3.1.conv2.fc2.weight\nlayer3.1.conv2.fc2.bias\nlayer3.1.conv3.weight\nlayer3.1.bn3.weight\nlayer3.1.bn3.bias\nlayer3.1.bn3.running_mean\nlayer3.1.bn3.running_var\nlayer3.1.bn3.num_batches_tracked\nlayer3.2.conv1.weight\nlayer3.2.bn1.weight\nlayer3.2.bn1.bias\nlayer3.2.bn1.running_mean\nlayer3.2.bn1.running_var\nlayer3.2.bn1.num_batches_tracked\nlayer3.2.conv2.conv.weight\nlayer3.2.conv2.bn0.weight\nlayer3.2.conv2.bn0.bias\nlayer3.2.conv2.bn0.running_mean\nlayer3.2.conv2.bn0.running_var\nlayer3.2.conv2.bn0.num_batches_tracked\nlayer3.2.conv2.fc1.weight\nlayer3.2.conv2.fc1.bias\nlayer3.2.conv2.bn1.weight\nlayer3.2.conv2.bn1.bias\nlayer3.2.conv2.bn1.running_mean\nlayer3.2.conv2.bn1.running_var\nlayer3.2.conv2.bn1.num_batches_tracked\nlayer3.2.conv2.fc2.weight\nlayer3.2.conv2.fc2.bias\nlayer3.2.conv3.weight\nlayer3.2.bn3.weight\nlayer3.2.bn3.bias\nlayer3.2.bn3.running_mean\nlayer3.2.bn3.running_var\nlayer3.2.bn3.num_batches_tracked\nlayer3.3.conv1.weight\nlayer3.3.bn1.weight\nlayer3.3.bn1.bias\nlayer3.3.bn1.running_mean\nlayer3.3.bn1.running_var\nlayer3.3.bn1.num_batches_tracked\nlayer3.3.conv2.conv.weight\nlayer3.3.conv2.bn0.weight\nlayer3.3.conv2.bn0.bias\nlayer3.3.conv2.bn0.running_mean\nlayer3.3.conv2.bn0.running_var\nlayer3.3.conv2.bn0.num_batches_tracked\nlayer3.3.conv2.fc1.weight\nlayer3.3.conv2.fc1.bias\nlayer3.3.conv2.bn1.weight\nlayer3.3.conv2.bn1.bias\nlayer3.3.conv2.bn1.running_mean\nlayer3.3.conv2.bn1.running_var\nlayer3.3.conv2.bn1.num_batches_tracked\nlayer3.3.conv2.fc2.weight\nlayer3.3.conv2.fc2.bias\nlayer3.3.conv3.weight\nlayer3.3.bn3.weight\nlayer3.3.bn3.bias\nlayer3.3.bn3.running_mean\nlayer3.3.bn3.running_var\nlayer3.3.bn3.num_batches_tracked\nlayer3.4.conv1.weight\nlayer3.4.bn1.weight\nlayer3.4.bn1.bias\nlayer3.4.bn1.running_mean\nlayer3.4.bn1.running_var\nlayer3.4.bn1.num_batches_tracked\nlayer3.4.conv2.conv.weight\nlayer3.4.conv2.bn0.weight\nlayer3.4.conv2.bn0.bias\nlayer3.4.conv2.bn0.running_mean\nlayer3.4.conv2.bn0.running_var\nlayer3.4.conv2.bn0.num_batches_tracked\nlayer3.4.conv2.fc1.weight\nlayer3.4.conv2.fc1.bias\nlayer3.4.conv2.bn1.weight\nlayer3.4.conv2.bn1.bias\nlayer3.4.conv2.bn1.running_mean\nlayer3.4.conv2.bn1.running_var\nlayer3.4.conv2.bn1.num_batches_tracked\nlayer3.4.conv2.fc2.weight\nlayer3.4.conv2.fc2.bias\nlayer3.4.conv3.weight\nlayer3.4.bn3.weight\nlayer3.4.bn3.bias\nlayer3.4.bn3.running_mean\nlayer3.4.bn3.running_var\nlayer3.4.bn3.num_batches_tracked\nlayer3.5.conv1.weight\nlayer3.5.bn1.weight\nlayer3.5.bn1.bias\nlayer3.5.bn1.running_mean\nlayer3.5.bn1.running_var\nlayer3.5.bn1.num_batches_tracked\nlayer3.5.conv2.conv.weight\nlayer3.5.conv2.bn0.weight\nlayer3.5.conv2.bn0.bias\nlayer3.5.conv2.bn0.running_mean\nlayer3.5.conv2.bn0.running_var\nlayer3.5.conv2.bn0.num_batches_tracked\nlayer3.5.conv2.fc1.weight\nlayer3.5.conv2.fc1.bias\nlayer3.5.conv2.bn1.weight\nlayer3.5.conv2.bn1.bias\nlayer3.5.conv2.bn1.running_mean\nlayer3.5.conv2.bn1.running_var\nlayer3.5.conv2.bn1.num_batches_tracked\nlayer3.5.conv2.fc2.weight\nlayer3.5.conv2.fc2.bias\nlayer3.5.conv3.weight\nlayer3.5.bn3.weight\nlayer3.5.bn3.bias\nlayer3.5.bn3.running_mean\nlayer3.5.bn3.running_var\nlayer3.5.bn3.num_batches_tracked\nlayer4.0.conv1.weight\nlayer4.0.bn1.weight\nlayer4.0.bn1.bias\nlayer4.0.bn1.running_mean\nlayer4.0.bn1.running_var\nlayer4.0.bn1.num_batches_tracked\nlayer4.0.conv2.conv.weight\nlayer4.0.conv2.bn0.weight\nlayer4.0.conv2.bn0.bias\nlayer4.0.conv2.bn0.running_mean\nlayer4.0.conv2.bn0.running_var\nlayer4.0.conv2.bn0.num_batches_tracked\nlayer4.0.conv2.fc1.weight\nlayer4.0.conv2.fc1.bias\nlayer4.0.conv2.bn1.weight\nlayer4.0.conv2.bn1.bias\nlayer4.0.conv2.bn1.running_mean\nlayer4.0.conv2.bn1.running_var\nlayer4.0.conv2.bn1.num_batches_tracked\nlayer4.0.conv2.fc2.weight\nlayer4.0.conv2.fc2.bias\nlayer4.0.conv3.weight\nlayer4.0.bn3.weight\nlayer4.0.bn3.bias\nlayer4.0.bn3.running_mean\nlayer4.0.bn3.running_var\nlayer4.0.bn3.num_batches_tracked\nlayer4.0.downsample.1.weight\nlayer4.0.downsample.2.weight\nlayer4.0.downsample.2.bias\nlayer4.0.downsample.2.running_mean\nlayer4.0.downsample.2.running_var\nlayer4.0.downsample.2.num_batches_tracked\nlayer4.1.conv1.weight\nlayer4.1.bn1.weight\nlayer4.1.bn1.bias\nlayer4.1.bn1.running_mean\nlayer4.1.bn1.running_var\nlayer4.1.bn1.num_batches_tracked\nlayer4.1.conv2.conv.weight\nlayer4.1.conv2.bn0.weight\nlayer4.1.conv2.bn0.bias\nlayer4.1.conv2.bn0.running_mean\nlayer4.1.conv2.bn0.running_var\nlayer4.1.conv2.bn0.num_batches_tracked\nlayer4.1.conv2.fc1.weight\nlayer4.1.conv2.fc1.bias\nlayer4.1.conv2.bn1.weight\nlayer4.1.conv2.bn1.bias\nlayer4.1.conv2.bn1.running_mean\nlayer4.1.conv2.bn1.running_var\nlayer4.1.conv2.bn1.num_batches_tracked\nlayer4.1.conv2.fc2.weight\nlayer4.1.conv2.fc2.bias\nlayer4.1.conv3.weight\nlayer4.1.bn3.weight\nlayer4.1.bn3.bias\nlayer4.1.bn3.running_mean\nlayer4.1.bn3.running_var\nlayer4.1.bn3.num_batches_tracked\nlayer4.2.conv1.weight\nlayer4.2.bn1.weight\nlayer4.2.bn1.bias\nlayer4.2.bn1.running_mean\nlayer4.2.bn1.running_var\nlayer4.2.bn1.num_batches_tracked\nlayer4.2.conv2.conv.weight\nlayer4.2.conv2.bn0.weight\nlayer4.2.conv2.bn0.bias\nlayer4.2.conv2.bn0.running_mean\nlayer4.2.conv2.bn0.running_var\nlayer4.2.conv2.bn0.num_batches_tracked\nlayer4.2.conv2.fc1.weight\nlayer4.2.conv2.fc1.bias\nlayer4.2.conv2.bn1.weight\nlayer4.2.conv2.bn1.bias\nlayer4.2.conv2.bn1.running_mean\nlayer4.2.conv2.bn1.running_var\nlayer4.2.conv2.bn1.num_batches_tracked\nlayer4.2.conv2.fc2.weight\nlayer4.2.conv2.fc2.bias\nlayer4.2.conv3.weight\nlayer4.2.bn3.weight\nlayer4.2.bn3.bias\nlayer4.2.bn3.running_mean\nlayer4.2.bn3.running_var\nlayer4.2.bn3.num_batches_tracked\n"
     ]
    }
   ],
   "source": [
    "for key in new_backbone_statedict:\n",
    "    print(key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "pretrain_model = torch.load(\"mask_rcnn_s50_fpn_syncbn-backbone+head_mstrain_1x_coco_20200926_125503-8a2c3d47.pth\")\n",
    "\n",
    "#处理backbone\n",
    "new_backbone_statedict = OrderedDict()\n",
    "for key in pretrain_model['state_dict']:\n",
    "    if key.startswith('backbone'):\n",
    "        new_backbone_statedict[key[len(\"backbone.\"):]] = pretrain_model['state_dict'][key]\n",
    "torch.save(new_backbone_statedict, \"coco_backbone_statedict.pth\")\n",
    "model.load_state_dict(new_backbone_statedict)\n",
    "del new_backbone_statedict\n",
    "\n",
    "#处理fpn\n",
    "temp_fpn_statedict = OrderedDict()\n",
    "for key in pretrain_model['state_dict']:\n",
    "    if not key.startswith(\"neck\"):\n",
    "        continue\n",
    "    temp_fpn_statedict[key[len(\"neck.\"):]] = pretrain_model['state_dict'][key]\n",
    "for i in range(1, 4):\n",
    "    del temp_fpn_statedict['fpn_convs.{}.conv.weight'.format(i)]\n",
    "    del temp_fpn_statedict['fpn_convs.{}.conv.bias'.format(i)]\n",
    "new_fpn_statedict = OrderedDict()\n",
    "for new_key, old_key in zip(fpn.state_dict(), temp_fpn_statedict):\n",
    "    new_fpn_statedict[new_key] = temp_fpn_statedict[old_key]\n",
    "del temp_fpn_statedict\n",
    "torch.save(new_fpn_statedict, \"coco_fpn_statedict.pth\")\n",
    "fpn.load_state_dict(new_fpn_statedict)\n",
    "del new_fpn_statedict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([2, 256, 128, 128])\n",
      "torch.Size([2, 512, 64, 64])\n",
      "torch.Size([2, 1024, 32, 32])\n",
      "torch.Size([2, 2048, 16, 16])\n"
     ]
    }
   ],
   "source": [
    "img = torch.randn(2, 3, 512, 512)\n",
    "outs = model(img)\n",
    "for out in outs:\n",
    "    print(out.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([2, 256, 128, 128])\n"
     ]
    }
   ],
   "source": [
    "fpn_outs = fpn(outs)\n",
    "print(fpn_outs.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([2, 1, 128, 128])\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "from resnest50_FPN import HuBMAP_model\n",
    "model = HuBMAP_model(\n",
    "    num_class = 1,\n",
    "    use_sigmoid=True,\n",
    "    model_path=\"./resnest50_fpn_coco.pth\"\n",
    ")\n",
    "img = torch.randn(2, 3, 512, 512)\n",
    "pred = model(img)\n",
    "print(pred.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from model import HuBMAP_model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([24, 1, 416, 416])\n"
     ]
    }
   ],
   "source": [
    "model = HuBMAP_model(\n",
    "    num_class = 1,\n",
    "    use_sigmoid=True,\n",
    "    model_path=\"./预训练权重/resnest50_fpn_coco.pth\"\n",
    ")\n",
    "model = model.cuda()\n",
    "img = torch.randn(24, 3, 416, 416).cuda()\n",
    "pred = model(img)\n",
    "print(pred.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = HuBMAP_model(\n",
    "    num_class = 1,\n",
    "    use_sigmoid=True,\n",
    "    model_path=\"./预训练权重/resnest50_fpn_coco.pth\"\n",
    ")\n",
    "img = torch.randn(2, 3, 512, 512)\n",
    "pred = model(img)\n",
    "print(pred.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10440"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "580*18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "580"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(10060-785)//16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "632"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(7603-1282)//10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Downloading: \"https://download.pytorch.org/models/resnet50-19c8e357.pth\" to C:\\Users\\Admin/.cache\\torch\\checkpoints\\resnet50-19c8e357.pth\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b6a36ed58ca14e00937a0f39346fe8c6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(FloatProgress(value=0.0, max=102502400.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import torchvision\n",
    "model = torchvision.models.segmentation.fcn_resnet50(False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torchvision\n",
    "import torch.nn as nn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = torchvision.models.segmentation.fcn_resnet50(pretrained = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "FCN(\n",
       "  (backbone): IntermediateLayerGetter(\n",
       "    (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)\n",
       "    (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "    (relu): ReLU(inplace=True)\n",
       "    (maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)\n",
       "    (layer1): Sequential(\n",
       "      (0): Bottleneck(\n",
       "        (conv1): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "        (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "        (downsample): Sequential(\n",
       "          (0): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        )\n",
       "      )\n",
       "      (1): Bottleneck(\n",
       "        (conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "        (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "      (2): Bottleneck(\n",
       "        (conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "        (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "    )\n",
       "    (layer2): Sequential(\n",
       "      (0): Bottleneck(\n",
       "        (conv1): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)\n",
       "        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "        (downsample): Sequential(\n",
       "          (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)\n",
       "          (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        )\n",
       "      )\n",
       "      (1): Bottleneck(\n",
       "        (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "      (2): Bottleneck(\n",
       "        (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "      (3): Bottleneck(\n",
       "        (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "        (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "    )\n",
       "    (layer3): Sequential(\n",
       "      (0): Bottleneck(\n",
       "        (conv1): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "        (downsample): Sequential(\n",
       "          (0): Conv2d(512, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          (1): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        )\n",
       "      )\n",
       "      (1): Bottleneck(\n",
       "        (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False)\n",
       "        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "      (2): Bottleneck(\n",
       "        (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False)\n",
       "        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "      (3): Bottleneck(\n",
       "        (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False)\n",
       "        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "      (4): Bottleneck(\n",
       "        (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False)\n",
       "        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "      (5): Bottleneck(\n",
       "        (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False)\n",
       "        (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "    )\n",
       "    (layer4): Sequential(\n",
       "      (0): Bottleneck(\n",
       "        (conv1): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False)\n",
       "        (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "        (downsample): Sequential(\n",
       "          (0): Conv2d(1024, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          (1): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        )\n",
       "      )\n",
       "      (1): Bottleneck(\n",
       "        (conv1): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(4, 4), dilation=(4, 4), bias=False)\n",
       "        (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "      (2): Bottleneck(\n",
       "        (conv1): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(4, 4), dilation=(4, 4), bias=False)\n",
       "        (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "        (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "        (relu): ReLU(inplace=True)\n",
       "      )\n",
       "    )\n",
       "  )\n",
       "  (classifier): FCNHead(\n",
       "    (0): Conv2d(2048, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "    (2): ReLU()\n",
       "    (3): Dropout(p=0.1, inplace=False)\n",
       "    (4): Conv2d(512, 21, kernel_size=(1, 1), stride=(1, 1))\n",
       "  )\n",
       ")"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.classifier[4] = nn.Conv2d(512, 1, kernel_size=(1, 1), stride=(1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([2, 2048, 64, 64])\n",
      "torch.Size([2, 1, 64, 64])\n",
      "torch.Size([2, 1, 512, 512])\n",
      "torch.Size([2, 1, 512, 512])\n"
     ]
    }
   ],
   "source": [
    "img = torch.randn(2, 3, 512, 512)\n",
    "pred = model(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6-final"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}